#coding=utf-8
'''
Created on 2010-9-14
@author: lxd
'''
import time
import random
import threading
p_lock = threading.RLock()
s_lock = threading.RLock()

def post_lock(fun):
    def _(*args, **kargs):
        p_lock.acquire()
        print '1'
        fun(*args, **kargs)
        p_lock.release()
    return _

class Test():
    def __my_post(self, str):
        print str
        time.sleep(random.random() * 2)
        
    def demo(self, str):
        __my_post(str)
        
t = Test()
for i in range(10000):
    t.demo('2')


    
#def my_post(str):
#    p_lock.acquire()
#    print str
#    time.sleep(random.random() * 2)
#    p_lock.release()
        
#def my_sleep(seconds):   
#    s_lock.acquire()
#    time.sleep(seconds)
#    s_lock.release()    
#     
#def my_wait(name, seconds):
#    last_time = time.time()
#    last_seconds = 0
#    while last_seconds < seconds:
#        my_post('%s:%s' % (time.time(), name)) 
#        my_sleep(3)
#        last_seconds = time.time() - last_time
#    
#class ThreadA(threading.Thread):
#    def run(self):
#        for i in range(10000):
#            my_post('%s:==================build house' % time.time())
#            my_wait('a wait', 20)
#            
#class ThreadB(threading.Thread):
#    def run(self):
#        for i in range(10000):
#            my_post('%s:=================plant tree' % time.time())
#            my_wait('b wait', 5)
#            
#threadA = ThreadA()
#threadA.setDaemon(True)
#threadB = ThreadB()
#threadB.setDaemon(True)
#
#threadA.start()
#threadB.start()
#threadA.join()
#threadB.join()
